﻿<UserControl x:Class="RIAServices.M2M.Demo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:models="clr-namespace:RIAServices.M2M.Demo" 
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.Resources>
        <models:MainPageModel x:Key="MainPageModel"/>
    </UserControl.Resources>
    <Grid DataContext="{Binding Source={StaticResource MainPageModel}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListBox SelectedItem="{Binding SelectedDog,Mode=TwoWay}" ItemsSource="{Binding DogList}" Grid.Row="1" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Dog: "/>
                        <TextBlock Text="{Binding DogId}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox Grid.Row="3" Grid.Column="0" SelectedItem="{Binding SelectedDogTrainer,Mode=TwoWay}" ItemsSource="{Binding SelectedDog.Trainers }" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Trainer: "/>
                        <TextBlock Text="{Binding TrainerId}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox Grid.Column="2" Grid.Row="1" SelectedItem="{Binding SelectedTrainer,Mode=TwoWay}" ItemsSource="{Binding TrainerList}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Trainer: "/>
                        <TextBlock Text="{Binding TrainerId}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox Grid.Column="2" Grid.Row="3" SelectedItem="{Binding SelectedTrainerDog,Mode=TwoWay}" ItemsSource="{Binding SelectedTrainer.Dogs}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Dog: "/>
                        <TextBlock Text="{Binding DogId}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>
        <ListBox Grid.Column="1" Grid.RowSpan="3" Grid.Row="1" ItemsSource="{Binding DogTrainers}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="DogTrainer: "/>
                        <TextBlock Text="{Binding Object1_Int32_Id0}"/>
                        <TextBlock Text=", "/>
                        <TextBlock Text="{Binding Object2_Int32_Id0}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center">
            <sdk:Label Content="DogSet"  />
            <sdk:Label Content="{Binding DogList.Count}"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center">
            <sdk:Label Content="DogTrainers"  />
            <sdk:Label Content="{Binding DogTrainers.Count}"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center">
            <sdk:Label Content="TrainerSet"  />
            <sdk:Label Content="{Binding TrainerList.Count}"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" >
            <sdk:Label Content="Dog.Trainers"  />
            <sdk:Label Content="{Binding SelectedDog.Trainers.Count}"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center">
            <sdk:Label Content="Trainer.Dogs"  />
            <sdk:Label Content="{Binding SelectedTrainer.Dogs.Count}"/>
        </StackPanel>
        <Grid Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="4" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <CheckBox Content="AutoSave" IsChecked="{Binding Path=AutoSave, Mode=TwoWay}" VerticalAlignment="Center" ToolTipService.ToolTip="Submit changes to server as soon as an entity/association has been created/deleted"/>
            <Button Content="Save" Grid.Column="1" Command="{Binding Save}" />
            <Button Content="AddTrainer" Grid.Column="2" Command="{Binding AddTrainer}"/>
            <Button Content="DeleteTrainer" Grid.Column="3" Command="{Binding DeleteTrainer}"/>
            <Button Content="CreateTrainer" Grid.Column="4" Command="{Binding CreateTrainer}"/>
            <Button Content="AddDog" Grid.Column="5" Command="{Binding AddDog}"/>
            <Button Content="DeleteDog" Grid.Column="6" Command="{Binding DeleteDog}"/>
            <Button Content="CreateDog" Grid.Column="7" Command="{Binding CreateDog}"/>
        </Grid>
    </Grid>
</UserControl>
